﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Project.Engine.Control;
using Project.Module.DAO;
using Project.Module.Model;
using Project.Module.DAO.BL;
using Project.Engine.Utilities;

namespace Project.Module.View
{
    public class ProductView : BasePageRazor
    {
        private int nguyenLieuLamBanhId = DefineUtil.nguyenLieuLamBanhId;
        private int nguyenLieuTrangTriId = DefineUtil.nguyenLieuTrangTriId;
        private int dungCuLamBanhId = DefineUtil.dungCuLamBanhId;
        private int khuonId = DefineUtil.khuonId;
        private int doGiaDungId = DefineUtil.doGiaDungId;
        private int sachId = DefineUtil.sachId;
        private int congThucId = DefineUtil.congThucId;
        private int lopHocId = DefineUtil.lopHocId;

        public string displayuser = String.Empty;
        public List<ProductModel> lophoc = null;
        public List<ProductModel> nguyenLieuLamBanh = null;
        private ProductBL productBl = new ProductBL();
        private EventBL eventBl = new EventBL();

        protected override void InitializePage()
        {
            base.InitializePage();
            if (Session["username"] != null && ConvertUtil.ToString(Session["username"]).Length > 0) {
                displayuser = ConvertUtil.ToString(Session["username"]);
            }
            GetListLopHoc();
            GetListNguyenLieuLamBanh();
        }

        private void GetListLopHoc()
        {
            this.lophoc = productBl.GetListProduct(lopHocId);
            if (this.lophoc != null)
            {
                foreach (var item in this.lophoc)
                {
                    item.url = StringUtil.UnicodeToKoDauUrl(StringUtil.ShortContent(item.Description, 5));
                    item.ImagePath = eventBl.GetImagePathById(item.ImageID);
                    item.title = StringUtil.ShortContent(item.Description, 5);
                    item.summary = StringUtil.ShortContent(item.Description, 20);
                    item.totalComment = (new FeedBackBL()).GetCommentProduct(item.ProductId, lopHocId).ToList().Count;
                }
            }
        }

        private void GetListNguyenLieuLamBanh()
        {
            this.nguyenLieuLamBanh = productBl.GetListProduct(nguyenLieuLamBanhId);
            if (this.nguyenLieuLamBanh != null)
            {
                foreach (var item in this.nguyenLieuLamBanh)
                {
                    item.url = StringUtil.UnicodeToKoDauUrl(StringUtil.ShortContent(item.Description, 5));
                    item.ImagePath = eventBl.GetImagePathById(item.ImageID);
                    item.title = StringUtil.ShortContent(item.Description, 5);
                    item.summary = StringUtil.ShortContent(item.Description, 20);
                    item.totalComment = (new FeedBackBL()).GetCommentProduct(item.ProductId, nguyenLieuLamBanhId).ToList().Count;
                }
            }
        }
    }
}
